package com.myapp.struts.action;

import com.myapp.hibernate.model.Boxeador;
import com.myapp.hibernate.util.BoxeadorUtil;
import com.myapp.struts.form.BoxeadoresForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author jiglrom
 */
public class GuardarBoxeadorAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        BoxeadoresForm formulario = (BoxeadoresForm)form;
        BoxeadorUtil boxeadorUtil = new BoxeadorUtil();
        String nombre = request.getParameter("nombre");
        String apellidos = request.getParameter("apellidos");
        int cganados = Integer.parseInt(request.getParameter("cganados"));
        int cperdidos = Integer.parseInt(request.getParameter("cperdidos"));
        
        Boxeador b = new Boxeador(nombre, apellidos, cganados, cperdidos);
        boxeadorUtil.guardar(b);
        return mapping.findForward(SUCCESS);
    }
}
